#ifndef LINK_MANAGER_HPP_
#	define LINK_MANAGER_HPP_

#	include "../Chess.hpp"
#	include "View.hpp"
#	include <map>
#	include <list>
#	include <QtGui>

#	include "CellWidget.hpp"

using namespace std;

class LinkManager : public QObject
{
	Q_OBJECT
	
	public:
		static LinkManager*	getInstance();
		~LinkManager();
		
		void	update( const map<unsigned short, MoveAction*> & mactions,
						const map<CastlingAction::Type, CastlingAction*>& actions,
						Chess::Color player);
	
	public slots:
		void	pieceSelect();			// when a piece of current player is clicked
		void	cellChoice();			// when a cell of the chessboard is chosen to be the destination
		void	pieceChoice();			// when a piece of the chessboard is chosen to be captured
		
		void	castlingSelect();		// when a castling button is clicked
		void	new_();					// when the new action of Game menu is triggered
		void	save();					// 			save
		void	load();					//			load
		
		
	private:
		static LinkManager* instance;
		LinkManager();
		bool		warning_playing();
		
		map<CellWidget*, map<PieceWidget*, unsigned short> >	cacodes; // <dst cell, < src piece, hash_key> >
		map<PieceWidget*, map<PieceWidget*, unsigned short> >	pacodes; // <dst piece, <src piece, hash_key> >
		map<PieceWidget*, list<CellWidget*> >					pacells; // <src piece, <dst cell> >
		map<PieceWidget*, list<PieceWidget*> >					papieces; // <src piece, <dst piece> >
		
		map<QPushButton*, CastlingAction*>						bcactions;
		
		PieceWidget*											selected;
};


#endif
